import 'dart:convert';
void main() {
  
  //https://dart.cn/libraries/dart-convert/#decoding-and-encoding-json
  // 解码 JSON 字符串
  var jsonString = '''
    [
      {"score": 40},
      {"score": 80}
    ]
  ''';

  var scores = jsonDecode(jsonString); // 将 JSON 字符串解码为 Dart 对象
  assert(scores is List); // 检查解码结果是否为 List
  assert(scores[0]['score'] == 40); // 检查第一个元素的 score 值

  // 编码 Dart 对象为 JSON 字符串
  var data = [
    {'score': 40},
    {'score': 80},
    {'score': 100, 'overtime': true, 'special_guest': null},
  ];

  var jsonText = jsonEncode(data); // 将 Dart 对象编码为 JSON 字符串
  print(jsonText); // 输出: [{"score":40},{"score":80},{"score":100,"overtime":true,"special_guest":null}]




//https://dart.cn/libraries/dart-convert/#decoding-and-encoding-utf-8-characters

List<int> utf8Bytes = [
  0xc3, 0x8e, 0xc3, 0xb1, 0xc5, 0xa3, 0xc3, 0xa9,
  0x72, 0xc3, 0xb1, 0xc3, 0xa5, 0xc5, 0xa3, 0xc3,
  0xae, 0xc3, 0xb6, 0xc3, 0xb1, 0xc3, 0xa5, 0xc4,
  0xbc, 0xc3, 0xae, 0xc5, 0xbe, 0xc3, 0xa5, 0xc5,
  0xa3, 0xc3, 0xae, 0xe1, 0xbb, 0x9d, 0xc3, 0xb1,
];

var funnyWord = utf8.decode(utf8Bytes);

assert(funnyWord == 'Îñţérñåţîöñåļîžåţîờñ');

}
